package cn.xuexiyuan.flinkstudy.checkpoint;

import org.apache.flink.api.java.tuple.Tuple2;
import org.apache.flink.streaming.connectors.redis.common.mapper.RedisCommand;
import org.apache.flink.streaming.connectors.redis.common.mapper.RedisCommandDescription;
import org.apache.flink.streaming.connectors.redis.common.mapper.RedisMapper;

/**
 * @Description:
 * @Author 左龙龙
 * @Date 21-3-29
 * @Version 1.0
 **/
public class MyRedisMapper implements RedisMapper<Tuple2<String, Integer>> {

    @Override
    public RedisCommandDescription getCommandDescription() {
        // 单词统计结果存储结构 Hash   wordd_cout: {单词1: 数量1, 单词2: 数量2}
        return new RedisCommandDescription(RedisCommand.HSET, "word_count");
    }

    @Override
    public String getKeyFromData(Tuple2<String, Integer> data) {
        return data.f0;
    }

    @Override
    public String getValueFromData(Tuple2<String, Integer> data) {
        return data.f1.toString();
    }
}